#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

void reverse(char* left, char* right)
{
    while (left < right)
    {
        char tmp = *left;
        *left = *right;
        *right = tmp;

        left++;
        right--;
    }
}


char* reverseStr(char* s, int k) {
    if (s == NULL)
        return "";
    int count = 0;
    int start = 0;
    int end = 0;
    for (int i = 0; i < strlen(s); i++)
    {
        count++;
        end++;
        if (2 * k == count)
        {
            count = 0;
            reverse(s + start, s + end - k - 1);
            start = end;
        }
        else if (strlen(s) - start < 2 * k && strlen(s) - start >= k)
        {
            reverse(s + start, s + start + k-1);
            break;
        }
        else if (strlen(s) - start  < k)
        {
            reverse(s + start, s + strlen(s) - 1);
            break;
        }
    }

    return s;
}




int main()
{
    char s[] = "abcdfg";
    char* p = reverseStr(s, 2);
    printf("%s\n", p);
    return 0;
}